<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class M_employee_access_grade_levels extends CI_Model
{
	function __construct()
    {
        parent::__construct();
		$this->load->model(array('M_users'));
    }
    
	function get_employees($id = '')
	{
		if($id == '')
		{
			$query = 'SELECT 
						employees.last_name, 
						employees.first_name,
						employees.middle_name,
						employees.role,
						employees.emp_id,
						users.username
					FROM
						employees
					LEFT JOIN
						users
					ON
						users.id = employees.id
					WHERE
						employees.role = "vice-principal"
					ORDER BY 
						employees.last_name
						';
			$q = $this->db->query($query);
			return $q->num_rows() > 0 ? $q->result() : FALSE;
		}
		else
		{
			$query = 'SELECT 
						employees.last_name, 
						employees.first_name,
						employees.middle_name,
						employees.role,
						employees.emp_id,
						users.username
					FROM
						employees
					LEFT JOIN
						users
					ON
						users.id = employees.id
					WHERE
						employees.emp_id = ?
						';
			$q = $this->db->query($query, array($id));
			return $q->num_rows() > 0 ? $q->row() : FALSE;
		}
	}
	
	function get_level_grades()
	{
		$query = 'SELECT 
					level_id,
					level_desc
				FROM
					levels
					';
		$q = $this->db->query($query);
		return $q->num_rows() > 0 ? $q->result() : FALSE;
	}
	
	function get_access_level($id = '')
	{
		if($id != '')
		{
		$query = 'SELECT 
					level_id
				FROM
					employee_access_grade_levels
				WHERE
					emp_id = ?
					';
		$q = $this->db->query($query, array($id));
		return $q->num_rows() > 0 ? $q->result() : FALSE;
		}else{
		$query = 'SELECT 
					employee_access_grade_levels.level_id,
					employee_access_grade_levels.emp_id,
					levels.level_desc
				FROM
					employee_access_grade_levels
				LEFT JOIN
					levels
				ON
					employee_access_grade_levels.level_id = levels.level_id
				
					';
		$q = $this->db->query($query);
		return $q->num_rows() > 0 ? $q->result() : FALSE;
		}
	}
	
	function delete_access_level($id = '')
	{
		if($id != '')
		{
			$this->db->delete('employee_access_grade_levels', array('emp_id' => $id));
			return TRUE;
		}else{
			return FALSE;
		}
	}
}
?>